package io.github.uicdb.et.data;

import io.github.uicdb.et.*;
import io.github.uicdb.et.element.BasicElement;
import net.minecraft.Util;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.neoforged.neoforge.common.data.LanguageProvider;

import java.util.Optional;

public class ZHLangProvider extends LanguageProvider {
    public ZHLangProvider(PackOutput output) {
        super(output, ElementalTheory.MODID, "zh_cn");
    }

    @Override
    protected void addTranslations() {
        for (ModElements value : ModElements.values()) {
            add(value.getElemental().getElement(), value.getChinese() + "元素");
            addPotion(value.getChinese(), value.getElemental().getPotionIncreasing());
            addEffect(() -> value.getElemental().getPotionIncreasing().value().getEffects().getFirst().getEffect().value(), value.getChinese() + "元素增幅");
            add(BuiltInRegistries.ATTRIBUTE, value.getElemental().getIncreasing().value(), value.getChinese() + "元素增幅");
        }
        add(BuiltInRegistries.ATTRIBUTE, ModAttributes.HEALTH_GETTER.value(),  "生命汲取");
        add(BuiltInRegistries.ATTRIBUTE, ModAttributes.HEALTH_RECOVERY.value(),  "恢复效率");
        add(BuiltInRegistries.ATTRIBUTE, ModAttributes.INJURE.value(),  "损伤");
        add(BuiltInRegistries.ATTRIBUTE, ModAttributes.TOUGHNESS.value(),  "控制抵抗");
        addDamage(ModElements.METAL, "%s被千刀万剐。", "%s在与%s的战斗中被千刀万剐。", "%s在与%s的战斗中被%s千刀万剐。");
        addDamage(ModElements.WOOD, "%s同化于自然。", "%s在与%s的战斗中同化与自然。", "%s在与%s的战斗中因为%s的攻击而同化于自然。");
        addDamage(ModElements.WATER, "%s湿透了。", "%s在与%s的战斗中湿透了。", "%s在与%s的战斗中被%s攻击导致湿透了");
        addDamage(ModElements.FIRE, "%s燃尽了。", "%s在与%s的战斗中燃尽了。", "%s在与%s的战斗中被%s攻击而燃尽了");
        addDamage(ModElements.EARTH, "%s安眠于大地。", "%s在与%s的战斗中安眠于大地。", "%s在与%s的战斗中被%s攻击导致安眠与大地");
        addDamage(ModElements.YIN, "%s堕于九幽。", "%s在与%s的战斗中堕于九幽。", "%s在与%s的战斗中被%s攻击导致堕于九幽");
        addDamage(ModElements.YANG, "%s阳极必反。", "%s在与%s的战斗中阳极必反。", "%s在与%s的战斗中被%s攻击导致阳极必反");
        add("itemGroup.elemental_theory.core", "元素论：核心");
        add("itemGroup.elemental_theory.tool", "元素论：工具");
        add("itemGroup.elemental_theory.armor", "元素论：装备");
        add("itemGroup.elemental_theory.consumed", "元素论：消耗品");
        add("itemGroup.elemental_theory.curio", "元素论：饰品");
        addCurioItem(ModItems.DOGE_HAPPY.asItem(), "狗之高兴","防御力的25%转化为最大生命值");
        add(ModItems.CUTOFF.asItem(), "断流");
        add(ModItems.DST.asItem(), "我不是药神");
        addCurioItem(ModItems.ENDER_LOCK.asItem(), "终界锁","15%概率免疫伤害并随机位移");
        add(ModItems.GUST.asItem(), "风球");
        add(ModItems.LIGHTNING_SWORD.asItem(), "雷霆召来");
        addCurioItem(ModItems.LUNAR_ECLIPSE.asItem(), "月蚀","给自己挂阴元素","给随机敌人挂阴元素");
        addCurioItem(ModItems.MAPLE_SORROW.asItem(), "枫之哀伤","近战必定暴击，但是暴击伤害只有150%","一分钟不攻击他人会扣除使用者生命");
        add(ModItems.NIGHT_DEMON.asItem(), "夜魔");
        addCurioItem(ModItems.PARALYSIS_RING.asItem(), "麻痹戒指","是兄弟就来砍我");
        addCurioItem(ModItems.PR_CRYSTEL.asItem(), "暗影晶石");
        addCurioItem(ModItems.RANDOM_CURIO.asItem(), "混沌灵石");
        addCurioItem(ModItems.SAFTY_HAT.asItem(), "安全帽","受到的伤害降低10%","为什么不是绿的？");
        add(ModItems.SALAMANDRA.get(), "飞龙炎");
        addCurioItem(ModItems.SHADOW_NECKLACE.asItem(), "暗影项链","当阴元素造成伤害时，造成额外50%法术伤害");
        addCurioItem(ModItems.SUNDEE.asItem(), "日耀","受到阳元素影响的敌人额外会受到伤害");
        add(ModItems.SUNLIT.asItem(), "日蚀");
        add(ModItems.THE_ENCHANTING_SCROLL.asItem(), "着魔卷轴");
        add(ModItems.WATER_SOURCE_STAFF.asItem(), "源流之杖");
        addCurioItem(ModItems.WHEAT_WAVE.asItem(), "麦动","受到致命攻击时50%概率判定不死，一小时内减少100%防御，80%最大生命","75%概率穿戴时直接死亡");
        addCurioItem(ModItems.WIND_WING.asItem(), "风灵翼","获得缓降");
        add("text.elemental_theory.element_data.0", "元素附魔类型：");
        add("text.elemental_theory.element_data.1", "元素附魔强度：");
        add("text.elemental_theory.element_data.2", "元素挂载时间：");
        add("text.elemental_theory.curio_init","右键使用以鉴定额外词条");
        add(ModBlocks.CLOUD_BLOCK.asItem(),"云");
        add(ModBlocks.EXTRACT_MACHINE.asItem(),"萃取台");
        add("gui.extract_recipe.title","元素萃取");
        add("gui.extract_screen.craft","萃取");
        add("gui.element_screen.craft","聚合");
        add("gui.turn_in_screen.craft","灌注");
        add(ModBlocks.WOOD_WOOD.asItem(),"灵木原木");
        add(ModBlocks.EARTH_FARMLAND.asItem(),"息壤");
        add(ModBlocks.ELEMENT_MACHINE.asItem(),"聚合台");
        add(ModBlocks.TURN_IN_MACHINE.asItem(),"灌注台");
        add(ModItems.WATER_WATER.asItem(),"无根水");
        add(ModBlocks.METAL_ORE.asItem(), "庚金矿");
    }

    private void addPotion(String chinese, Holder<Potion> potionEDB) {
        add(Potion.getName(Optional.of(potionEDB), Items.POTION.getDescriptionId() + ".effect."), chinese + "元素增幅药水");
        add(Potion.getName(Optional.of(potionEDB), Items.SPLASH_POTION.getDescriptionId() + ".effect."), "喷溅型" + chinese + "元素增幅药水");
        add(Potion.getName(Optional.of(potionEDB), Items.LINGERING_POTION.getDescriptionId() + ".effect."), "滞留型" + chinese + "元素增幅药水");
    }

    public void addDamage(ModElements elements, String value, String byPlayer, String byItem) {
        String common = "death.attack.elemental_theory." + elements.name().toLowerCase();
        String player = "death.attack.elemental_theory." + elements.name().toLowerCase() + ".player";
        String item = "death.attack.elemental_theory." + elements.name().toLowerCase() + ".item";
        add(common, value);
        add(player, byPlayer);
        add(item, byItem);
    }

    public void addCurioItem(net.minecraft.world.item.Item item, String name, String... texts) {
        String key = BuiltInRegistries.ITEM.getKey(item).getPath();
        if (texts.length > 0) {
            if (texts.length == 1) {
                add("text.elemental_theory." + key, texts[0]);
            } else {
                for (int i = 0; i < texts.length; i++) {
                    add("text.elemental_theory." + key + "." + i, texts[i]);
                }
            }
        }
        add(item,name);

    }

    public <T> void add(Registry<T> registry, T object, String name) {
        var k = registry.getKey(object);
        var id = Util.makeDescriptionId(registry.key().location().getPath(), k);
        super.add(id, name);
    }

    public void add(BasicElement element, String name) {
        add(ElementalTheory.BASIC_ELEMENT_REGISTRY, element, name);
    }

}
